The y component of a direction/length pair - how far down (negative length: up) a step of that length in that direction reaches, matching the room’s own y-down convention.
dir_y(direction, length) -> real| Name | Type |
|---|---|
direction | real |
length | real |
real
The vertical component of a direction/length pair - how far down (negative length: up) a step of that length in that direction reaches, matching the room's own y-down convention. -(length * angle_sin(direction)), already worked out - the minus is the same "screen Y grows downward, maths angles do not" correction every direction-shaped field in the engine shares, gravity_dir included (it uses direction's own convention exactly, not a separate one).
Paired with dir_x, this turns a direction-and-speed into the hsp/vsp that actual movement understands - the exact shape a bounce or a launch needs.
// Bounce off a horizontal paddle: flip the vertical half of the travel, keep the sideways
// half exactly as it was - the reflection a ball bouncing off a flat surface always needs.
// Assumes speed is left at 0 and hsp/vsp carry all of this object's own motion instead - the
// simplest shape to reason about, though not required: hsp's own note has the full story on
// how hsp/vsp and speed/direction can mix on the same instance.
direction = -direction;
hsp = dir_x(direction, 3);
vsp = dir_y(direction, 3);Reflecting direction across the horizontal axis (-direction) keeps the sideways part of the travel and flips the up/down part - exactly what bouncing off a flat paddle or floor does to a ball's own path. dir_x/dir_y then turn that new direction straight into a fresh hsp/vsp kick.
Unlike dist_to/sqrt, there is no squaring anywhere in this one - angle_sin never exceeds a magnitude of 1, so the result never exceeds length itself, for any length real can hold.
-(length * angle_sin(direction)) - the minus is the same "screen y grows downward, math angles do not" correction gravity_dir’s own field already documents: direction 90 is "straight up" in this engine, and dir_y(90, length) comes out negative, matching that.